package com.fr.report.painter;

import com.fr.base.FRFont;
import com.fr.base.Style;
import com.fr.base.core.ComparatorUtils;
import com.fr.base.core.list.IntList;
import com.fr.base.core.serializable.Point2DSerializable;
import com.fr.base.xml.XMLPrintWriter;
import com.fr.base.xml.XMLableReader;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.geom.Line2D.Double;
import java.awt.geom.Point2D;
import java.awt.geom.Point2D.Double;
import java.awt.geom.Rectangle2D;
import java.awt.geom.Rectangle2D.Double;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.ArrayList;
import java.util.List;

public class BiasTextPainter extends AbstractPainter
{
  private String text = null;
  private List angleList = new ArrayList();
  private transient List lineEndList = new ArrayList();
  private List textList = new ArrayList();
  private List isLargeDiagonal = new ArrayList();
  private boolean isCenter = false;
  private boolean isBackSlash = false;

  private void readObject(ObjectInputStream paramObjectInputStream)
    throws ClassNotFoundException, IOException
  {
    int j;
    paramObjectInputStream.defaultReadObject();
    int i = paramObjectInputStream.readInt();
    if (i > 0)
    {
      if (this.lineEndList == null)
        this.lineEndList = new ArrayList();
      this.lineEndList.clear();
      for (j = 0; j < i; ++j)
      {
        Object localObject = paramObjectInputStream.readObject();
        if (localObject != null)
          this.lineEndList.add(((Point2DSerializable)localObject).getPoint2D());
      }
    }
  }

  private void writeObject(ObjectOutputStream paramObjectOutputStream)
    throws IOException
  {
    paramObjectOutputStream.defaultWriteObject();
    paramObjectOutputStream.writeInt(this.lineEndList.size());
    for (int i = 0; i < this.lineEndList.size(); ++i)
    {
      Point2D localPoint2D = (Point2D)this.lineEndList.get(i);
      paramObjectOutputStream.writeObject(new Point2DSerializable(localPoint2D));
    }
  }

  public BiasTextPainter(String paramString)
  {
    setText(paramString);
  }

  private void generateTextListAndAngleList()
  {
    this.angleList.clear();
    this.lineEndList.clear();
    this.textList.clear();
    this.isLargeDiagonal.clear();
    int i = getText().length();
    IntList localIntList = new IntList();
    localIntList.add(0);
    for (int j = 0; j < i; ++j)
      if (getText().charAt(j) == '|')
      {
        k = localIntList.get(localIntList.size() - 1);
        if (j != k)
        {
          localIntList.add(j + 1);
          String str = getText().substring(k, j);
          getTextList().add(str);
        }
        else
        {
          localIntList.add(j + 1);
          getTextList().add(" ");
        }
      }
    j = localIntList.get(localIntList.size() - 1);
    if (j == i)
      getTextList().add(" ");
    else
      getTextList().add(getText().substring(localIntList.get(localIntList.size() - 1), i));
    for (int k = 1; k < localIntList.size(); ++k)
      if (this.isBackSlash)
        getAngleList().add(new Double(90 / localIntList.size() * (localIntList.size() - k)));
      else
        getAngleList().add(new Double(90 / localIntList.size() * k));
  }

  public void setAngle(int paramInt, double paramDouble1, double paramDouble2, double paramDouble3)
  {
    double d2;
    double d3;
    getAngleList().set(paramInt, new Double(paramDouble1));
    double d1 = paramDouble3 / paramDouble2;
    if (d1 > Math.tan(paramDouble1 / 180.0D * 3.141592653589793D))
    {
      getLargeDiagonal().set(paramInt, Boolean.FALSE);
      if (this.isBackSlash)
      {
        d2 = paramDouble2;
        d3 = -paramDouble2 * Math.tan(paramDouble1 / 180.0D * 3.141592653589793D);
      }
      else
      {
        d2 = paramDouble2;
        d3 = paramDouble2 * Math.tan(paramDouble1 / 180.0D * 3.141592653589793D);
      }
    }
    else
    {
      getLargeDiagonal().set(paramInt, Boolean.TRUE);
      if (this.isBackSlash)
      {
        d3 = -paramDouble3;
        d2 = paramDouble3 / Math.tan(paramDouble1 / 180.0D * 3.141592653589793D);
      }
      else
      {
        d3 = paramDouble3;
        d2 = paramDouble3 / Math.tan(paramDouble1 / 180.0D * 3.141592653589793D);
      }
    }
    getLineEndList().set(paramInt, new Point2D.Double(d2, d3));
  }

  public void generateLineEndList(double paramDouble1, double paramDouble2)
  {
    Object localObject = getLineEndList();
    if (localObject == null)
    {
      localObject = new ArrayList();
      setLineEndList((List)localObject);
    }
    ((List)localObject).clear();
    double d1 = paramDouble2 / paramDouble1;
    for (int i = 0; i < getAngleList().size(); ++i)
    {
      double d2;
      double d3;
      double d4 = ((Double)getAngleList().get(i)).doubleValue() / 180.0D * 3.141592653589793D;
      if (d1 > Math.tan(d4))
      {
        getLargeDiagonal().add(Boolean.FALSE);
        if (this.isBackSlash)
        {
          d2 = paramDouble1;
          d3 = -paramDouble1 * Math.tan(d4);
        }
        else
        {
          d2 = paramDouble1;
          d3 = paramDouble1 * Math.tan(d4);
        }
      }
      else
      {
        getLargeDiagonal().add(Boolean.TRUE);
        if (this.isBackSlash)
        {
          d3 = -paramDouble2;
          d2 = paramDouble2 / Math.tan(d4);
        }
        else
        {
          d3 = paramDouble2;
          d2 = paramDouble2 / Math.tan(d4);
        }
      }
      ((List)localObject).add(new Point2D.Double(d2, d3));
    }
  }

  public String getText()
  {
    return this.text;
  }

  public void setText(String paramString)
  {
    this.text = paramString;
    generateTextListAndAngleList();
  }

  public List getAngleList()
  {
    return this.angleList;
  }

  public void setAngleList(List paramList)
  {
    this.angleList = paramList;
  }

  public List getLineEndList()
  {
    return this.lineEndList;
  }

  public void setLineEndList(List paramList)
  {
    this.lineEndList = paramList;
  }

  public List getTextList()
  {
    return this.textList;
  }

  public void setTextList(List paramList)
  {
    this.textList = paramList;
  }

  public List getLargeDiagonal()
  {
    return this.isLargeDiagonal;
  }

  public void setLargeDiagonal(List paramList)
  {
    this.isLargeDiagonal = paramList;
  }

  public void setIsBackSlash(boolean paramBoolean)
  {
    this.isBackSlash = paramBoolean;
  }

  public boolean getIsBackSlash()
  {
    return this.isBackSlash;
  }

  public void paint(Graphics paramGraphics, int paramInt1, int paramInt2, Style paramStyle)
  {
    Graphics2D localGraphics2D = (Graphics2D)paramGraphics;
    paintBiasString(localGraphics2D, new Rectangle2D.Double(0.0D, 0.0D, paramInt1, paramInt2), new Rectangle2D.Double(0.0D, 0.0D, paramInt1, paramInt2), this.text, paramStyle);
  }

  private void paintBiasString(Graphics2D paramGraphics2D, Rectangle2D paramRectangle2D1, Rectangle2D paramRectangle2D2, String paramString, Style paramStyle)
  {
    int j;
    if ((paramString == null) || (paramString.indexOf("|") == -1))
      return;
    Graphics2D localGraphics2D = (Graphics2D)paramGraphics2D.create();
    if (this.isBackSlash)
      localGraphics2D.translate(paramRectangle2D1.getX(), paramRectangle2D1.getY() + paramRectangle2D1.getHeight());
    else
      localGraphics2D.translate(paramRectangle2D1.getX(), paramRectangle2D1.getY());
    localGraphics2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    localGraphics2D.setStroke(localGraphics2D.getStroke());
    if (paramString.length() > 0)
    {
      if (paramStyle == null)
        paramStyle = Style.DEFAULT_STYLE;
      FRFont localFRFont = paramStyle.getFRFont();
      if (!(ComparatorUtils.equals(localFRFont, localGraphics2D.getFont())))
        localGraphics2D.setFont(localFRFont);
      Color localColor = localFRFont.getForeground();
      if (!(ComparatorUtils.equals(localColor, localGraphics2D.getPaint())))
        localGraphics2D.setPaint(localColor);
      generateLineEndList(paramRectangle2D1.getWidth(), paramRectangle2D1.getHeight());
      int i = this.textList.size();
      BiasZone[] arrayOfBiasZone = new BiasZone[i];
      if (i == 2)
      {
        boolean bool1 = false;
        setAngle(0, Math.atan2(paramRectangle2D1.getHeight(), paramRectangle2D1.getWidth()) * 180.0D / 3.141592653589793D, paramRectangle2D1.getWidth(), paramRectangle2D1.getHeight());
        if (this.isBackSlash)
        {
          arrayOfBiasZone[0] = new BiasZone(paramRectangle2D1, 90.0D, ((Double)getAngleList().get(0)).doubleValue(), (String)getTextList().get(0), paramStyle, 1, bool1, this.isBackSlash);
          arrayOfBiasZone[1] = new BiasZone(paramRectangle2D1, ((Double)getAngleList().get(0)).doubleValue(), 0.0D, (String)getTextList().get(1), paramStyle, 2, bool1, this.isBackSlash);
        }
        else
        {
          arrayOfBiasZone[0] = new BiasZone(paramRectangle2D1, 0.0D, ((Double)getAngleList().get(0)).doubleValue(), (String)getTextList().get(0), paramStyle, 1, bool1, this.isBackSlash);
          arrayOfBiasZone[1] = new BiasZone(paramRectangle2D1, ((Double)getAngleList().get(0)).doubleValue(), 90.0D, (String)getTextList().get(1), paramStyle, 2, bool1, this.isBackSlash);
        }
      }
      else if (i == 3)
      {
        double d1;
        double d2;
        boolean bool2;
        if (this.isBackSlash)
        {
          d1 = 180.0D * Math.atan(2.0D * paramRectangle2D1.getHeight() / 3.0D / paramRectangle2D1.getWidth()) / 3.141592653589793D;
          d2 = 180.0D * (1.570796326794897D - Math.atan(2.0D * paramRectangle2D1.getWidth() / 3.0D / paramRectangle2D1.getHeight())) / 3.141592653589793D;
          setAngle(0, d2, paramRectangle2D1.getWidth(), paramRectangle2D1.getHeight());
          setAngle(1, d1, paramRectangle2D1.getWidth(), paramRectangle2D1.getHeight());
          bool2 = false;
          arrayOfBiasZone[0] = new BiasZone(paramRectangle2D1, 90.0D, ((Double)getAngleList().get(0)).doubleValue(), (String)getTextList().get(0), paramStyle, 1, bool2, this.isBackSlash);
          arrayOfBiasZone[1] = new BiasZone(paramRectangle2D1, ((Double)getAngleList().get(0)).doubleValue(), ((Double)getAngleList().get(1)).doubleValue(), (String)getTextList().get(1), paramStyle, 3, this.isCenter, this.isBackSlash);
          arrayOfBiasZone[2] = new BiasZone(paramRectangle2D1, ((Double)getAngleList().get(1)).doubleValue(), 0.0D, (String)getTextList().get(2), paramStyle, 2, bool2, this.isBackSlash);
        }
        else
        {
          d1 = 180.0D * Math.atan(2.0D * paramRectangle2D1.getHeight() / 3.0D / paramRectangle2D1.getWidth()) / 3.141592653589793D;
          d2 = 180.0D * (1.570796326794897D - Math.atan(2.0D * paramRectangle2D1.getWidth() / 3.0D / paramRectangle2D1.getHeight())) / 3.141592653589793D;
          setAngle(0, d1, paramRectangle2D1.getWidth(), paramRectangle2D1.getHeight());
          setAngle(1, d2, paramRectangle2D1.getWidth(), paramRectangle2D1.getHeight());
          bool2 = false;
          arrayOfBiasZone[0] = new BiasZone(paramRectangle2D1, 0.0D, ((Double)getAngleList().get(0)).doubleValue(), (String)getTextList().get(0), paramStyle, 1, bool2, this.isBackSlash);
          arrayOfBiasZone[1] = new BiasZone(paramRectangle2D1, ((Double)getAngleList().get(0)).doubleValue(), ((Double)getAngleList().get(1)).doubleValue(), (String)getTextList().get(1), paramStyle, 3, this.isCenter, this.isBackSlash);
          arrayOfBiasZone[2] = new BiasZone(paramRectangle2D1, ((Double)getAngleList().get(1)).doubleValue(), 90.0D, (String)getTextList().get(2), paramStyle, 2, bool2, this.isBackSlash);
        }
      }
      else
      {
        if (this.isBackSlash)
        {
          arrayOfBiasZone[0] = new BiasZone(paramRectangle2D1, 90.0D, ((Double)getAngleList().get(0)).doubleValue(), (String)getTextList().get(0), paramStyle, 3, this.isCenter, this.isBackSlash);
          arrayOfBiasZone[(i - 1)] = new BiasZone(paramRectangle2D1, ((Double)getAngleList().get(getAngleList().size() - 1)).doubleValue(), 0.0D, (String)getTextList().get(getTextList().size() - 1), paramStyle, 3, this.isCenter, this.isBackSlash);
          j = 1;
          while (true)
          {
            if (j >= i - 1)
              break label1462;
            arrayOfBiasZone[j] = new BiasZone(paramRectangle2D1, ((Double)getAngleList().get(j - 1)).doubleValue(), ((Double)getAngleList().get(j)).doubleValue(), (String)getTextList().get(j), paramStyle, 3, this.isCenter, this.isBackSlash);
            ++j;
          }
        }
        arrayOfBiasZone[0] = new BiasZone(paramRectangle2D1, 0.0D, ((Double)getAngleList().get(0)).doubleValue(), (String)getTextList().get(0), paramStyle, 3, this.isCenter, this.isBackSlash);
        arrayOfBiasZone[(i - 1)] = new BiasZone(paramRectangle2D1, ((Double)getAngleList().get(getAngleList().size() - 1)).doubleValue(), 90.0D, (String)getTextList().get(getTextList().size() - 1), paramStyle, 3, this.isCenter, this.isBackSlash);
        for (j = 1; j < i - 1; ++j)
          arrayOfBiasZone[j] = new BiasZone(paramRectangle2D1, ((Double)getAngleList().get(j - 1)).doubleValue(), ((Double)getAngleList().get(j)).doubleValue(), (String)getTextList().get(j), paramStyle, 3, this.isCenter, this.isBackSlash);
      }
      for (j = 0; j < i; ++j)
        label1462: arrayOfBiasZone[j].paintZone(localGraphics2D);
      for (j = 0; j < getLineEndList().size(); ++j)
      {
        Point2D localPoint2D = (Point2D)getLineEndList().get(j);
        localGraphics2D.draw(new Line2D.Double(0.0D, 0.0D, localPoint2D.getX(), localPoint2D.getY()));
      }
    }
  }

  public boolean equals(Object paramObject)
  {
    if (!(paramObject instanceof BiasTextPainter))
      return false;
    return ((ComparatorUtils.equals(getText(), ((BiasTextPainter)paramObject).getText())) && (ComparatorUtils.equals(new Boolean(getIsBackSlash()), new Boolean(((BiasTextPainter)paramObject).isBackSlash))));
  }

  public String toString()
  {
    return "";
  }

  public void readXML(XMLableReader paramXMLableReader)
  {
    super.readXML(paramXMLableReader);
    if ((paramXMLableReader.isChildNode()) && (paramXMLableReader.getTagName().equals("IsBackSlash")))
    {
      String str;
      if ((str = paramXMLableReader.getAttr("value")) != null)
        setIsBackSlash(Boolean.valueOf(str).booleanValue());
    }
    if (paramXMLableReader.isCharacters())
      setText(paramXMLableReader.getContent());
  }

  public void writeXML(XMLPrintWriter paramXMLPrintWriter)
  {
    super.writeXML(paramXMLPrintWriter);
    paramXMLPrintWriter.startTAG("IsBackSlash").attr("value", this.isBackSlash).end().textNode(this.text);
  }
}